package com.drcoffee.drcoffeemall.service.impl;

import com.drcoffee.drcoffeemall.entry.ExceptionRecord;
import com.drcoffee.drcoffeemall.mapper.ExceptionRecordMapper;
import com.drcoffee.drcoffeemall.service.ExceptionRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;

@Service
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public class ExceptionRecordServiceImpl implements ExceptionRecordService {
    @Autowired
    ExceptionRecordMapper exceptionRecordMapper;

    @Override
    public boolean addException(ExceptionRecord exceptionRecord) {
        long l = System.currentTimeMillis(); //获取时间戳效率最高
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        exceptionRecord.setDate( dateFormat.format(l));
        return exceptionRecordMapper.addException(exceptionRecord);
    }
}
